angular.module("cityApp", []).controller("cityController", function($scope, $http) {

    $scope.getCityList = function(){
        $http({
            method: 'GET',
            url: 'http://localhost:8360/home/index/getcitylist'
        }).success(function (data) {
            $scope.cityList = data.data;
            
        });
    }
    $scope.getCityList();


	$scope.city = {};
	$scope.addCity = function(){
		$('#addcity').show();
		/*alert();*/
	}
	$scope.addtrue = function(){
		$('#addcity').hide();
		var time = getCurrentTime();
		$http({
                method: 'GET',
                params:{name:$scope.city.name,time:time},
                url: 'http://localhost:8360/home/index/addcity'
        }).success(function (data) {
        	alert("添加城市成功");
            $scope.getCityList();
        });
	}
	$scope.addfalse = function(){
		$('#addcity').hide();
	}



    $scope.runCity = function(){
        $http({
            method: 'GET',
            url: 'http://localhost:8360/home/index/task'
        }).success(function (data) {
            alert('定时任务已开启');
        });
    }


});

// 获取当前时间，格式为：2013-10-09
function getCurrentTime() {
    var Nowdate = new Date();
    var day = (Nowdate.getDate() + "");
    day = day.length == 1 ? ("0" + day) : day;
    var month = ((Nowdate.getMonth() + 1) + "");
    month = month.length == 1 ? ("0" + month) : month;
    var hour = Nowdate.getHours()+"";
    hour = hour.length==1 ? ("0" + hour) : hour;
    var minute = Nowdate.getMinutes()+"";
    minute = minute.length==1 ? ("0" + minute) : minute;
    t = [Nowdate.getFullYear(), month, day];
    var dat = t.join('-')+' '+hour+':'+minute;
    return dat;
}

$(function(){
	//alert(1);
});